//列表最大行数
var MAX_ROWS = 100;
(function($) {
	var server = "http://localhost";

	window.$$ = Dom7;
	//高版本jquery，需要使用传统的方式浅层进行序列化，来适应jsp
	$.ajaxSettings.traditional = true;
	
	//初始化seajs
	seajs.config({
		base : "./modules/"
	});

	//framework7初始化
	var app = new Framework7({
                pushState: true,
                swipePanel: 'left',
                material:true,
                smartSelectBackText : "返回",
                smartSelectPopupCloseText : "关闭",
                smartSelectPickerCloseText : "完成",
                modalButtonOk : "确定",
                modalButtonCancel : "取消",
                modalUsernamePlaceholder : "用户名",
                modalPasswordPlaceholder : "密码",
                modalPreloaderTitle : "加载中……",
                notificationCloseButtonText : "关闭",
                ajaxLinks:"a.router"
            });

	var _ajax = $.ajax;
    $.extend($, {
    	server : server,
        app : app,
        mainView : app.addView('.view-main', {
            domCache: true //enable inline pages
        }),
        toUrl: function(uri) {
            if(uri.substring(0, 1) == "/") {
                return this.server + uri;
            }
            return uri;
        },
        ajax : function(obj) {
            obj.url = $.toUrl(obj.url);
            return _ajax(obj);
        },
        alert : function() {
            var args = arguments;
            if(arguments.length < 2) {
                args = [arguments[0], "提示"];
            }
        	app.alert.apply(app, args);
        },
        confirm : function() {
            var args = arguments;
            if(arguments.length < 2) {
                args = [arguments[0], "请确认"];
            } else if(arguments.length < 3 && typeof(arguments[1]) == "function") {
                args = [arguments[0], "请确认", arguments[1]];
            }
        	app.confirm.apply(app, args);
        },
        toast : function(msg, duration) {
            var toast = app.toast(msg ? msg : '请稍后……', '', {
                duration: duration ? duration : 2000
            });
        	toast.show();
        },
        back: function() {
            $.mainView.router.back();
        }
    });

    //响应结果处理
	$.ajaxSetup({
		
		complete:function(xhr, status) {
			if(xhr.status == 200 || xhr.status == 0) {
				return;
			}
			//未认证
			if(xhr.status == 401) {
				//跳转登录页

			} else if(xhr.status == 403) {
				$.alert("您无权访问次功能.");
			} else {
				$.toast("错误代码: "+xhr.status+"， 错误信息："+xhr.statusText);
			}
		},
        error:function(xhr, options, exc) {
            if(xhr.status == 0) {
                $.alert("请检查网络.");
            }
        }
		
	});
    //校验设置
    $.validators.required.error = "请填写{*}.";
    $.extend({
        validateResult : function(isValidate, fields, passes, errors) {
            if(!isValidate) {
                $.toast(errors[0].error);
            }
        }
    });

})(jQuery ? jQuery : (Zepto ? Zepto : {}));